package com.cnbot.toolkit.string;

import java.text.DecimalFormat;

/**
 * m描述字符串处理
 * @author wzz
 */
public class StringUtils {

	/**
	 * 获取服务器地址
	 * @param urlString
	 * @return
	 */
	public static String getHostName(String urlString) {
		String head = "";
		int index = urlString.indexOf("://");
		if (index != -1) {
			head = urlString.substring(0, index + 3);
			urlString = urlString.substring(index + 3);
		}
		index = urlString.indexOf("/");
		if (index != -1) {
			urlString = urlString.substring(0, index + 1);
		}
		return head + urlString;
	}

	/**
	 * 字节换算
	 * @param var0
	 * @return
	 */
	public static String getDataSize(long var0) {
		DecimalFormat var2 = new DecimalFormat("###.00");
		return var0 < 1024L ? var0 + "bytes"
				: (var0 < 1048576L ? var2.format((double) ((float) var0 / 1024.0F)) + "KB"
						: (var0 < 1073741824L ? var2.format((double) ((float) var0 / 1024.0F / 1024.0F)) + "MB"
								: (var0 < 0L ? var2.format((double) ((float) var0 / 1024.0F / 1024.0F / 1024.0F)) + "GB" : "error")));
	}

	public static int getAngle(double modelHeight, double stature, double distance) {
		System.out.println("参数: E: " + modelHeight + " S:" + stature + "D:" + distance);
		double radians = (modelHeight - stature - 5) / distance;
		System.out.println("角度： " + (int) Math.atan((modelHeight - stature - 5) / distance) + " tan = " + Math.toDegrees(Math.atan(radians)));
		return (int) Math.toDegrees(Math.atan(radians));
	}

}
